//
//  MLXConfigTool.m
//  MLXLaunchModule
//
//  Created by SY on 2018/11/30.
//

#import "MLXConfigTool.h"

@implementation MLXConfigTool
+(NSDictionary *)readProjectRootAttributeConfig{
    NSString *path = [self getBoundPath:@"ProjectConfig"];
    NSDictionary *dic = [NSDictionary dictionaryWithContentsOfURL:[NSURL fileURLWithPath:path]];
    NSMutableDictionary *attributesDic = [NSMutableDictionary dictionary];
    NSMutableArray *titles = [NSMutableArray array];
    NSMutableArray *imageNameNols = [NSMutableArray array];
    NSMutableArray *imageNameSels = [NSMutableArray array];
    NSMutableArray *VCs = [NSMutableArray array];
    for (NSDictionary *attributeDic in dic[@"rootAttribute"]) {
        if ([attributeDic[@"activation"] boolValue]) {
            [titles addObject:attributeDic[@"title"]];
            [imageNameNols addObject:attributeDic[@"imageName_nol"]];
            [imageNameSels addObject:attributeDic[@"imageName_sel"]];
            Class aClass = NSClassFromString(attributeDic[@"moduleProtocolName"]);
            if (!aClass) {
                NSCAssert(NO, @"项目中没有这个类");
            }else{
                id module = [[aClass alloc] init];
                id vc = [module performSelector:NSSelectorFromString(attributeDic[@"ActionSEL"])];
                    MLXNavigationViewController *nav = [[MLXNavigationViewController alloc] initWithRootViewController:vc];
                
                [VCs addObject:nav];
            }
        }
    }
    attributesDic[@"title"] = titles;
    attributesDic[@"imageNameNols"] = imageNameNols;
    attributesDic[@"imageNameSels"] = imageNameSels;
    attributesDic[@"VCs"] = VCs;
    return attributesDic;
}

+(NSString *)getBoundPath:(NSString *)fileName{
    NSBundle *bundle = [NSBundle bundleForClass:self];
    NSString *path = [bundle pathForResource:fileName ofType:@"plist" inDirectory:@"MLXConfig.bundle"];
    return  path;
}
@end
